/**************************************************************
  > File Name: 763.c
  > Author: LuoLiang
  > Mail: 1204553475@qq.com 
  > Created Time: 2022年02月10日 星期四 18时00分40秒
 **************************************************************/
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define length 1024
#define SIZE 26


int *partitionLabels(char * s, int* returnSize)
{
	int i, j, left, right;
	int s_buf[26];
	int *arr = (int *)calloc(length, sizeof(int));

	for (i = 0; i < strlen(s); i++)	
	{
		s_buf[s[i]-'a'] = i;
	}

	for (i = 0; i < strlen(s); i = j)
	{
		right = s_buf[s[i]-'a'];
		for (j = i, left = j; j <= right; j++)
		{
			if (s_buf[s[j]-'a'] > right)
			{
				right = s_buf[s[j]-'a'];
			}
		}
		if (returnSize > 0)
		{
			right -= left;
		}
		arr[(*returnSize)++] = right + 1;
	}
	return arr;
}

int main(int argc, char **argv)
{
	char *s = "ababcbacadefegdehiahklij";
	int returnSize = 0;
	int *ret;

	ret = partitionLabels(s, &returnSize);

	for (int i; i < returnSize; i++)
	{
		printf("%d,",ret[i]);
	}

    exit(0);
}
